import cv2
import numpy

img = cv2.imread("F:\AI\Course\Chapter3\home.JPG")

#SIFT
sift = cv2.xfeatures2d.SIFT_create()
keypoints = sift.detect(img, None)
img1 = img.copy()
img1 = cv2.drawKeypoints(img, keypoints, img1, color=(0,255,0))
cv2.imshow('Detected SIFT keypoints', img1)
cv2.waitKey(0)

#FAST
fast = cv2.FastFeatureDetector_create()
keypoints2 = fast.detect(img, None)
img2 = img.copy()
img2 = cv2.drawKeypoints(img, keypoints2, img2, color=(0,255,0))
cv2.imshow('Detected FAST keypoints', img2)
cv2.waitKey(0)

#ORB
orb = cv2.ORB_create()
keypoints3 = orb.detect(img, None)
img3 = img.copy()
img3 = cv2.drawKeypoints(img, keypoints3, img3, color=(0,255,0))
cv2.imshow('Detected ORB keypoints', img3)
cv2.waitKey(0)


# 展示不同的图片
titles = ['Source','Detected SIFT keypoints','Detected FAST keypoints', 'Detected ORB keypoints']
imgs = [img, img1, img2, img3]

for i in range(5):
    cv2.imshow(titles[i], imgs[i])
    cv2.waitKey(1000000)

